<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: orders.php 518 2015-02-27 13:25:40Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 518 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2015-02-27 13:25:40 +0000 (Fri, 27 Feb 2015) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
require_once(DIR_FS_CATALOG.DIR_WS_CLASSES.'class.phpmailer.php');
require_once(DIR_FS_INC.'inc.php_mail.php');
require_once(DIR_FS_INC.'inc.add_tax.php');
require_once(DIR_FS_INC.'inc.validate_vatid_status.php');
require_once(DIR_FS_INC.'inc.get_attributes_model.php');
require_once(DIR_FS_INC.'inc.build_order_id.php');

require_once(DIR_FS_INC.'inc.get_pdf_nr.php');

$smarty = new Smarty();
require (DIR_WS_CLASSES.'currencies.php');
$currencies = new currencies();

if ((($_GET['action'] == 'edit') || ($_GET['action'] == 'update_order') || ($_GET['action'] == 'update_box')) && ($_GET['oID'])) {
	$oID = $_GET['oID'];

	$orders = $db->db_query("SELECT orders_id FROM ".TABLE_ORDERS." WHERE orders_id = ".$db->db_prepare($oID));
	$order_exists = true;
	if ($orders->_numOfRows == 0) {
		$order_exists = false;
		$message_stack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
	}
}

require(DIR_WS_CLASSES.'order.php');
if ((($_GET['action'] == 'edit') || ($_GET['action'] == 'update_order') || ($_GET['action'] == 'update_box')) && ($order_exists)) {
	$order = new order($_GET['oID']);

	require_once(DIR_FS_INC.'inc.get_pdf.php');
	if(isset($_GET['pdf']) && $_GET['pdf'] == 'print_order') {
		if(isset($_POST['what_to_do']) && $_POST['what_to_do'] == 'pdf_rechnung_loeschen') {
			$pdf_pfad = get_pdf($_POST['oID'], false, false, false, true);
			if(file_exists($pdf_pfad)) {
				unlink($pdf_pfad);
				$db->db_query("DELETE FROM ".TABLE_ORDERS_PDF." WHERE order_id = ".$db->db_prepare($_POST['oID']));
				$_SESSION['msg']['dl'] = '<div class="success_msg">'.PDF_DELETE_SUCCESS.'</div>';
				if($_POST['pdf_rechnung_senden'] !='1')
					redirect(FILENAME_ORDERS.'?page='.$_POST['page'].'&oID='.$_POST['oID'].'&action=edit#pdf');
			}
		} elseif(isset($_POST['what_to_do']) && ($_POST['what_to_do'] == 'bill' || $_POST['what_to_do'] == 'delivery')) {
			if($_POST['what_to_do'] == 'delivery') {
				define('PDF_LIEFERSCHEIN', true);
				$_GET['type'] = 'lieferschein';
			} else
				define('PDF_LIEFERSCHEIN', false);

			include_once('create_pdf.php');
		}
	}

    if($_POST['pdf_rechnung_senden']=='1' ) {
		    $check_status = $db->db_query("	SELECT
	    										o.customers_name, o.customers_email_address, o.orders_status, o.date_purchased, op.bill_name
	    									FROM
	    										".TABLE_ORDERS." o, 
	    										".TABLE_ORDERS_PDF." op
	    									WHERE
	    										o.orders_id = ".$db->db_prepare($oID)."
	    									AND
	    										op.order_id = ".$db->db_prepare($oID));

      	$smarty->assign('language', $_SESSION['language']);

	    $smarty->assign('NAME', $check_status->fields['customers_name']);
	    $smarty->assign('ORDER_NR', get_pdf_nr($oID, true));
	    $smarty->assign('ORDER_LINK', catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id='.$oID, 'SSL'));
	    $smarty->assign('ORDER_DATE', date_long($check_status->fields['date_purchased']));
	    $smarty->assign('NOTIFY_COMMENTS', $notify_comments);
	    $smarty->assign('ORDER_STATUS', $orders_status_array[$status]);

		$smarty->caching = false;
		require_once(DIR_FS_INC.'inc.get_mail_body.php');
		$html_mail = $smarty->fetch('html:pdf_mail');
		$html_mail .= $signatur_html;
		$txt_mail = $smarty->fetch('txt:pdf_mail');
		$txt_mail .= $signatur_text;
		require_once(DIR_FS_INC.'inc.get_mail_data.php');
		$mail_data = get_mail_data('pdf_mail');

        $email_pdf_bill_subject = str_replace('{$date}', date_long($check_status->fields['date_purchased']), $mail_data['EMAIL_SUBJECT']);
		$email_pdf_bill_name = str_replace('{$store_name}', STORE_NAME, $mail_data['EMAIL_ADDRESS_NAME']);

		$pdf_pfad = get_pdf($_POST['oID'], false, false, false, true);
		$pdf_name = get_pdf($_POST['oID'], false, false, true);

		php_mail($mail_data['EMAIL_ADDRESS'],
		         $email_pdf_bill_name,
		         $check_status->fields['customers_email_address'],
		         $check_status->fields['customers_name'],
		         '',
		         $mail_data['EMAIL_REPLAY_ADDRESS'],
				 $mail_data['EMAIL_REPLAY_ADDRESS_NAME'],
		         $pdf_pfad,
		         $pdf_name,
		         $email_pdf_bill_subject,
		         $html_mail,
		         $txt_mail);

		$db->db_query("UPDATE ".TABLE_ORDERS_PDF." SET notified_date = NOW(), customer_notified = '1' WHERE order_id = '".$_POST['oID']."'");
      	$_SESSION['msg']['sm'] = '<div class="success_msg">Die PDF Rechnung wurde als Email verschickt.</div>';
      	if($_GET['action'] == 'update_box') {
      		unset($_GET['pdf_email']);
      		unset($_GET['update_box']);
      		redirect(FILENAME_ORDERS.'?page='.$_GET['page'].'&oID='.$_GET['oID']);
      	} else {
      		redirect(href_link(FILENAME_ORDERS, get_all_get_params(array('pdf_email'))).'#pdf');
      	}
	}
}

$lang = $db->db_query("SELECT languages_id FROM ".TABLE_LANGUAGES." WHERE directory = '".$order->info['language']."'");
$lang = $lang->fields['languages_id'];

if(!isset($lang))
	$lang = $_SESSION['languages_id'];

$orders_statuses = array();
$orders_status_array = array();
$orders_status = $db->db_query("SELECT orders_status_id, orders_status_name FROM ".TABLE_ORDERS_STATUS." WHERE language_id = '".$lang."'");

while (!$orders_status->EOF) {
	$orders_statuses[] = array('id' => $orders_status->fields['orders_status_id'], 'text' => $orders_status->fields['orders_status_name']);
	$orders_status_array[$orders_status->fields['orders_status_id']] = $orders_status->fields['orders_status_name'];
	$orders_status->MoveNext();
}

switch($_GET['action']) {
	case 'send' :
		include('includes/modules/order_send.php');

		redirect(href_link(FILENAME_ORDERS, 'oID='.$_GET['oID']));

	case 'update_order' :
	case 'multi_status' :
		if(isset($_GET['del_id']) && $_GET['del_id'] !='') {
			$db->db_query("DELETE FROM ".TABLE_ORDERS_STATUS_HISTORY." WHERE orders_status_history_id = '".intval($_GET['del_id'])."' ");
			$message_stack->add_session(SUCCESS_HISTORY_DELETE, 'success');
		} else
			include('includes/modules/order_update_order.php');

		if($_GET['action'] == 'update_order')
			redirect(href_link(FILENAME_ORDERS, get_all_get_params(array('action','del_id')).'action=edit#comment'));
		else
			redirect(href_link(FILENAME_ORDERS, get_all_get_params(array('oID', 'action'))));
		break;

	case 'deleteconfirm' :
		include('includes/modules/order_deleteconfirm.php');

		redirect(href_link(FILENAME_ORDERS, get_all_get_params(array('oID', 'action'))));
		break;

	case 'afterbuy_send' :
		$oID = $db->db_prepare($_GET['oID']);
		require_once (DIR_FS_CATALOG.'includes/classes/class.afterbuy.php');
		$aBUY = new afterbuy_functions($oID);
		if ($aBUY->order_send())
			$aBUY->process_order();

		break;
}

require(DIR_WS_INCLUDES.'metatag.php'); ?>
</head>
<body>
<?php
require (DIR_WS_INCLUDES.'header.php');

$order = new order($_GET['oID']);

if (isset($_GET['print_oID'])) {
	if ($_GET['print_invoice'] == 'on') {
		echo '<script type="text/javascript">var invoice'.$i.' = window.open(\''.href_link(FILENAME_PRINT_ORDER,'print_oID='.$_GET['print_oID']).'\', \'invoice\', \'toolbar=0, width=640, height=600\')</script>';
	}
	if ($_GET['print_customer'] == 'on') {
		echo '<script type="text/javascript">window.open("'.(ENABLE_SSL_CATALOG == 'true' ? HTTPS_CATALOG_SERVER : HTTP_CATALOG_SERVER) . '/' . FILENAME_PRINT_ORDER . '?oID='.$_GET['print_oID'].'")</script>';
	}
	if ($_GET['print_packingslip'] == 'on') {
		echo '<script type="text/javascript">var packingslip'.$i.' = window.open(\''.href_link(FILENAME_PRINT_PACKINGSLIP,'print_oID='.$_GET['print_oID']).'\', \'packingslip\', \'toolbar=0, width=640, height=600\')</script>';
	}
}
?>

<script type="text/javascript">
	$(function(){
		$.fx.speeds._default = 1000;
		$("#comment_form").dialog({autoOpen:false,show:"fade",hide:"explode",width:510,modal:true});
		$(".comment_button").click(function(){$("#comment_form").dialog("open");return false;});
		$('.send_comment').click(function(){$('.comment_form').submit()});
	});
</script>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
	</td>
    <td  class="boxCenter" valign="top">
    <table width="100%" cellspacing="0" cellpadding="2">
<?php
if (($_GET['action'] == 'edit') && ($order_exists)) {
	$last_status = $db->db_query("SELECT 
									orders_status_id, 
									date_added 
								FROM 
									".TABLE_ORDERS_STATUS_HISTORY." 
								WHERE 
									orders_id = ".$db->db_prepare($oID)." 
								ORDER BY 
									date_added DESC LIMIT 1");
?>
  <tr>
      <td width="100%">
      	<?php
      		$prev_order = $db->db_query("SELECT orders_id, customers_firstname, customers_lastname FROM ".TABLE_ORDERS." WHERE orders_id > '".(int)$_GET['oID']."' ORDER BY orders_id ASC LIMIT 1");
      		$next_order = $db->db_query("SELECT orders_id, customers_firstname, customers_lastname FROM ".TABLE_ORDERS." WHERE orders_id < '".(int)$_GET['oID']."' ORDER BY orders_id DESC LIMIT 1");
      	?>
      	<table width="100%" cellpadding="6" class="subTable">
      		<tr>
      			<th class="subTable_head" width="50%">
      				<?php
      				if($prev_order->_numOfRows)
						echo '<a href="orders.php?'.getMenuID('orders').'&oID='.$prev_order->fields['orders_id'].'&action=edit">&laquo; '.$prev_order->fields['orders_id'].' - '.$prev_order->fields['customers_lastname'].', '.$prev_order->fields['customers_firstname'].'</a>';
      				?>
      			</th>
      			<th class="subTable_head" style="text-align:right">
      				<?php
      				if($next_order->_numOfRows)
      					echo '<a href="orders.php?'.getMenuID('orders').'&oID='.$next_order->fields['orders_id'].'&action=edit">'.$next_order->fields['orders_id'].' - '.$next_order->fields['customers_lastname'].', '.$next_order->fields['customers_firstname'].' &raquo;</a>';
      				?>
      			</th>
      		</tr>
      	</table>
				<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
		    <td class="pageHeading"><?php echo HEADING_TITLE.' Nr : '.build_order_id($order->info['date_purchased'], $oID, 'confirm').' - '.$order->info['purchased_date']; ?></td>
		  </tr>
		</table>
		<a class="button" href="<?php echo href_link(FILENAME_ORDERS, get_all_get_params(array('action')))?>"><?php echo BUTTON_BACK; ?></a>
		<a class="button" href="<?php echo href_link(FILENAME_ORDERS_EDIT, 'oID='.$_GET['oID'].'&cID='.$order->customer['ID']);?>"><?php echo BUTTON_EDIT ?></a>
		<a class="button comment_button" href="javascript:void(0)">Kommentare/Status</a>
		<div id="comment_form" title="<?php echo TABLE_HEADING_COMMENTS; ?>" style="display:none">
			<?php echo draw_form('status', FILENAME_ORDERS, get_all_get_params(array('action')).'action=update_order', 'POST', 'class="comment_form"'); ?>
	    		<table cellspacing="0" cellpadding="4" width="100%">
	            <tr>
	                <td colspan="2">
	            		<?php echo ENTRY_STATUS; ?> <?php echo draw_pull_down_menu('status', $orders_statuses, $last_status->fields['orders_status_id']); ?>
	                </td>
	            </tr>
	            <tr>
	            	<td colspan="2">
	                	<?php echo draw_textarea_field('comments', 'soft', '60', '5', '', 'style="width:99.5%"'); ?>
	                </td>
	            </tr>
	            <tr>
	            	<td>
	                	<label for="notify"><?php echo ENTRY_NOTIFY_CUSTOMER; ?> </label>
	                	<input type="checkbox" name="notify" value="on" id="notify" />
	                </td>
	            	<td>
	                	<label for="notify_comments"><?php echo ENTRY_NOTIFY_COMMENTS; ?></label>
	                	<input type="checkbox" name="notify_comments" value="on" id="notify_comments" />
	                </td>
	            </tr>
	            <tr>
	            	<td align="right" colspan="2">
	                	<a class="button comment_button" href="javascript:void(0)"><?php echo BUTTON_CANCEL ?></a> 
	                	<a href="javascript:void(0)" class="button send_comment"><?php echo BUTTON_SEND; ?></a>
	                </td>
	            </tr>
	            <tr>
	            	<td colspan="2">
	            		<table width="100%">
	                	<?php
							$orders_history = $db->db_query("SELECT
																	orders_status_history_id, orders_status_id, date_added, customer_notified, comments
																FROM
																	".TABLE_ORDERS_STATUS_HISTORY."
																WHERE
																	orders_id = ".$db->db_prepare($oID)."
																ORDER BY
																	date_added");
							if ($orders_history->_numOfRows) {
								$i = 1;
								while (!$orders_history->EOF) {
									echo '<tr><td style="position:relative">';
									echo '<span class="history_del_link">
											<a href="'.href_link(FILENAME_ORDERS, 'action=update_order&del_id='.$orders_history->fields['orders_status_history_id'].'&oID='.$oID).'">
												'.image('images/icons/document--minus.png', 'Eintrag l&ouml;schen','', '', 'style="position:relative; top:4px; margin-right:3px"').'
											</a>
										  </span>';
									echo image('images/icons/document.png', '','', '', 'style="position:relative; top:4px; margin-right:3px"');
									echo '<small>'.datetime_short($orders_history->fields['date_added'], DATE_TIME_FORMATED).'</small> | ';
									echo  ($orders_history->fields['orders_status_id']!='0') ? '<b>'.$orders_status_array[$orders_history->fields['orders_status_id']].'</b> | ' : '';
									if($orders_history->fields['customer_notified'] == '1') {
										echo '<small>'.CUSTOMER_NOTIFIED.'</small> '.image('images/tick.gif', ICON_TICK,'', '', 'style="position:relative; top:4px"').'<br />';
									} else {
										echo '<small'.CUSTOMER_NOT_NOTIFIED.'</small> '.image('images/icons/minus-circle.png', ICON_TICK,'', '', 'style="position:relative; top:4px"').'<br />';
									}
									echo '</td></tr><tr class="bb"><td>';
									echo($orders_history->fields['comments'] !='') ? '<div class="order_comment">'.nl2br(strip_tags($orders_history->fields['comments'])).'</div>' : '';
									echo '</td></tr>';
									$i++;
									$orders_history->MoveNext();
								}
							} else
								echo TEXT_NO_ORDER_HISTORY;
						?>
						</table>
	                </td>
	            </tr>
	        </table></form>
	    </div>
		<?php include('includes/modules/pdf_rechnung.php'); ?>
 	  </td>
   	  </tr>
      <tr>
      	<td>
        	<div class="left">
            	<table class="subTable" cellspacing="0" cellpadding="4">
	            	<tr>
	                	<th colspan="2" class="subTable_head"><?php echo TEXT_ORDER .' '. $oID; ?></th>
	                </tr>
	            	<tr>
	                	<td><?php echo ENTRY_DATE_PURCHASED; ?></td>
	                    <td><?php echo $order->info['date_purchased']; ?></td>
	                </tr>
	                <tr>
	                	<td><?php echo TEXT_SATUS; ?></td>
	                    <td>
	                    	<?php
								echo $orders_status_array[$last_status->fields['orders_status_id']];
							?>
	                    </td>
	                </tr>
	                <tr>
	                	<td valign="top"><?php echo ENTRY_PAYMENT_METHOD; ?></td>
	                	<td>
	                		<?php include(DIR_WS_MODULES.'order_payments.php') ?>
	                	</td>
	                </tr>
	                <tr>
                        <td valign="top"><?php echo ENTRY_SHIPPING_INFO; ?></td>
                        <td>
                        	<?php
								if($order->info['shipping_method'] !='') {
									include_once(DIR_FS_CATALOG.'includes/classes/class.price.php');
									$price = new price($_SESSION['currency'], $_SESSION['customers_status']['customers_status_id']);
									echo $order->info['shipping_method']; ?> = <b><?php echo $price->format($order->info['shipping_cost'], true) ?></b>
							<?php } else {
								echo '<em>Es liegen keine Versandinformationen vor.</em>';
							} ?>
                        </td>
                    </tr>
	            </table>
	            <?php
	            	$billing_address = address_format($order->billing['format_id'], $order->billing, 1, '', '<br />');
	            	$shipping_address = address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br />');
	            ?>
	            <table class="subTable" cellspacing="0" cellpadding="4">
	            	<?php if($billing_address != $shipping_address)
	                	echo '<tr><th class="subTable_head" colspan="2" align="center" style="text-align:center">'.NOT_THE_SAME_ADDRESS.'</th></tr>';
	                ?>
	            	<tr>
	                	<th class="subTable_head" width="50%"><?php echo ENTRY_BILLING_ADDRESS; ?></th>
	                	<th class="subTable_head">
	                		<?php echo ENTRY_SHIPPING_ADDRESS; ?>
	                	</th>
	                </tr>
	                <tr>
	                	<td><?php echo $billing_address ?></td>
	                	<td><?php echo $shipping_address ?></td>
	                </tr>
	            </table>
            </div>

            <div class="right">
            	<table class="subTable" cellspacing="0" cellpadding="4" width="100%">
                    <tr>
                        <th colspan="2" class="subTable_head">
                            <?php echo TEXT_CUSTOMERS_INFO; ?> <?php if($order->customer['csID']!='') echo ' - '.$order->customer['csID']; ?>
                        </th>
                    </tr>
                    <tr>
                        <td><?php echo TEXT_CUSTOMERS_NAME; ?></td>
                        <td><a href="<?php echo href_link('customers.php?page=1&cID='.$order->customer[ID].'&action=edit'); ?>"><?php echo $order->customer['name']; ?></a></td>
                    </tr>
                    <tr>
                        <td><?php echo ENTRY_EMAIL_ADDRESS; ?></td>
                        <td><a href="mailto:<?php echo $order->customer['email_address']; ?>"><?php echo $order->customer['email_address']; ?></a></td>
                    </tr>
                    <tr>
                    	<td><?php echo ENTRY_TELEPHONE; ?></td>
                		<td><?php echo $order->customer['telephone']; ?></td>
                    </tr>
                    <?php if($order->customer['vat_id'] !='') { ?>
                    <tr>
                    	<td class="main"><?php echo ENTRY_CUSTOMERS_VAT_ID; ?></td>
                		<td class="main"><?php echo $order->customer['vat_id']; ?></td>
                    </tr>
                    <?php } ?>
                    <tr>
                    	<td><?php echo TEXT_CUSTOMERS_STATUS; ?></td>
                        <td><?php echo $order->info['status_name']; ?></td>
                    </tr>
                    <tr>
                    	<td><?php echo TEXT_ORDER_IP; ?></td>
                        <td><?php echo $order->customer['cIP']; ?></td>
                    </tr>
					<tr>
						<td>
							<?php echo CUSTOMERS_MEMO; ?>
						</td>
						<td>
							<?php
					            $memo_count =$db->db_query("SELECT count(*) AS count FROM ".TABLE_CUSTOMERS_MEMO." WHERE customers_id='".$order->customer['ID']."'");
					        	echo $memo_count->fields['count']; ?>  <a style="cursor:pointer" onclick="javascript:window.open('<?php echo href_link(FILENAME_POPUP_MEMO,'ID='.$order->customer['ID']); ?>', 'popup', 'scrollbars=yes, width=500, height=500')">(<?php echo DISPLAY_MEMOS; ?>)
						</td>
					</tr>
                </table>
            </div>
        	<br style="clear:both" />
        </td>
      </tr>
		<?php
		$download = $db->db_query("SELECT orders_products_filename, download_maxdays, download_count, download_ip, download_time, orders_products_download_id FROM ".TABLE_ORDERS_PRODUCTS_DOWNLOAD." WHERE orders_id = '". $oID ."' ");
		if($download->_numOfRows) {

			function formatBytes($bytes, $precision = 2) {
			    $units = array('B', 'KB', 'MB', 'GB', 'TB');
			    $bytes = max($bytes, 0);
			    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
			    $pow = min($pow, count($units) - 1);
			    $bytes /= pow(1024, $pow);
			    return round($bytes, $precision).' '.$units[$pow];
			}
		?>
			<tr>
				<td>
					<table class="subTable" cellspacing="0" cellpadding="4" width="100%">
						<tr>
							<th class="subTable_head" width="100%">
								Downloads
							</th>
						</tr>
						<tr>
							<td>
								<?php echo draw_form('downloads', FILENAME_ORDERS, get_all_get_params(array('action')).'action=update_order&download','post'); ?>
								<table border="0" width="100%" cellspacing="0" cellpadding="2" class="dataTable">
									<tr class="dataTableHeadingRow">
										<td class="dataTableHeadingContent"><?php echo NAME_OF_FILE; ?></td>
										<td class="dataTableHeadingContent"><?php echo VALID_THROUGH; ?></td>
										<td class="dataTableHeadingContent" align="center"><?php echo OPEN_DOWNLOADS; ?></td>
										<td class="dataTableHeadingContent"><?php echo LAST_DOWNLOAD; ?></td>
										<td class="dataTableHeadingContent"><?php echo DOWNLOAD_IP; ?></td>
										<td class="dataTableHeadingContent"><?php echo REACTIVATE; ?></td>
									</tr>
									<?php
									while(!$download->EOF) {
									?>
									<tr>
										<td>
											<?php
												echo $download->fields['orders_products_filename'];
												$size = filesize(DIR_FS_CATALOG.'download/'.$download->fields['orders_products_filename']);
												echo ' | '.formatBytes($size);
											?>
										</td>
										<td>
											<?php
												$dt = $order->info['date_purchased'];
												$date = date("d.m.Y", mktime(substr($dt,11,2),substr($dt,14,2),0,substr($dt,5,2),substr($dt,8,2)+$download->fields['download_maxdays'],substr($dt,0,4)));
												echo $date;
											?>
										</td>
										<td align="center">
											<?php echo $download->fields['download_count'];	?>
										</td>
										<td>
											<?php echo ($download->fields['download_time'] != '0000-00-00 00:00:00')?$download->fields['download_time']:OPEN_DOWNLOAD;?>
										</td>
										<td align="center">
											<?php echo ($download->fields['download_ip']!='')?$download->fields['download_ip']:'-';?>
										</td>
										<td>
											<?php
											 	if($download->fields['download_count'] <= 0)
												echo draw_input_field('download['.$download->fields['orders_products_download_id'].']', '0', 'size=3').' <input type="image" src="images/icons/update.gif" style="position:relative;top:4px" />'; ?>
										</td>
									</tr>
									<?php $download->MoveNext(); } ?>
								</table>
								</form>
							</td>
						</tr>
					</table>
				</td>
			</tr>
	<?php } ?>
      <tr>
      <td>
      	<table class="subTable" cellspacing="0" cellpadding="4" width="100%">
	        <tr>
	            <th class="subTable_head" width="100%">
	                <?php echo PRODUCTS; ?>
	            </th>
	        </tr>
	        <tr>
	            <td>
	                <table border="0" width="100%" cellspacing="0" cellpadding="2" class="dataTable">
	                  <tr class="dataTableHeadingRow">
	                    <td class="dataTableHeadingContent" colspan="3"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
	                    <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
	                    <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_EXCLUDING_TAX; ?></td>
							<?php
	                            if ($order->products[0]['allow_tax'] == 1) {
	                        ?>
	                    <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TAX; ?></td>
	                    <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_INCLUDING_TAX; ?></td>
						<?php
	                        }
	                    ?>
	                    <td class="dataTableHeadingContent" align="right"><?php
							echo TABLE_HEADING_TOTAL_INCLUDING_TAX;
							if ($order->products[$i]['allow_tax'] == 1) {
								echo ' (exkl.)';
							}
						?></td>
	                  </tr>
	                    <?php
	                        for ($i = 0, $n = sizeof($order->products); $i < $n; $i ++) {
	                        //echo_e($order->products, 'E');
	                            echo '<tr class="'.(($i%2==0)?'dataTableRow':'').'">'."\n".'
	                            		<td valign="top" width="1">';
		                            	if(file_exists('../'.$order->products[$i]['image']))
		                           			echo '<img style="border: 1px solid #ccc" src="../'.$order->products[$i]['image'].'" alt="" />';
		                           		else
		                           			echo '&nbsp;';
		                           	echo '</td>'."\n";
	                           		echo '<td valign="top" align="right" width="1">'.$order->products[$i]['qty'].'x </td>'."\n".'
	                                    <td valign="top"><b>'.$order->products[$i]['name'].'</b>';
	                              if ($order->products[$i]['options_description'] != '') {
                              		echo '<br>';
	                              	foreach($order->products[$i]['options_description'] as $opt) {
	                              		if ($opt['option_value'] != '')
		                              		echo $opt['option_name'] . ": " . $opt['option_value'] . '<br>';
	                              	}
	                              }
	                            if (sizeof($order->products[$i]['attributes']) > 0)
	                                for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j ++)
	                                    echo '<br /><nobr><small>&nbsp;<i> - '.$order->products[$i]['attributes'][$j]['option'].': '.$order->products[$i]['attributes'][$j]['value'].'</i></small></nobr>';
	                            echo '</td>'."\n".'<td valign="middle">';

	                            if ($order->products[$i]['model'] != '')
	                                echo $order->products[$i]['model'];
	                            else
	                                echo '<br />';

	                            if (sizeof($order->products[$i]['attributes']) > 0) {
	                                for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j ++) {
	                                    $model = get_attributes_model($order->products[$i]['id'], $order->products[$i]['attributes'][$j]['value'],$order->products[$i]['attributes'][$j]['option']);
	                                    if ($model != '')
	                                        echo $model.'<br />';
	                                    else
	                                        echo '<br />';
	                                }
	                            }

	                            echo '</td>'."\n".'
	                                <td align="right" valign="top">'.format_price($order->products[$i]['final_price'] / $order->products[$i]['qty'], 1, $order->info['currency'], $order->products[$i]['allow_tax'], $order->products[$i]['tax']).'</td>'."\n";

	                            if ($order->products[$i]['allow_tax'] == 1) {
	                                echo '<td align="right" valign="top">';
	                                echo display_tax_value($order->products[$i]['tax']).'%';
	                                echo '</td>'."\n";
	                                echo '<td align="right" valign="top"><b>';

	                                echo format_price($order->products[$i]['final_price'] / $order->products[$i]['qty'], 1, $order->info['currency'], 0, 0);

	                                echo '</b></td>'."\n";
	                            }
	                            echo '<td align="right" valign="top"><b>'.format_price(($order->products[$i]['final_price']), 1, $order->info['currency'], 0, 0).'</b></td>'."\n";
	                            echo '</tr>'."\n";
	                        }
	                    ?>
	                </table>
	            </td>
	        </tr>
	    </table>
    	</td>
      </tr>
      <tr>
      	<td>
			<div class="left">
				&nbsp;
        	</div>
			<div class="right">
				<table class="subTable" cellpadding="4" width="100%">
			        <tr>
			            <th class="subTable_head" width="100%">
			                <?php echo TOTAL; ?>
			            </th>
			        </tr>
			        <tr>
			            <td style="background:#FCF5DD">
			                <table cellpadding="2" width="100%">
								<?php
									for ($i = 0, $n = sizeof($order->totals); $i < $n; $i ++) {
										echo '<tr class="'.$order->totals[$i]['class'].'">'."\n".'
												<td align="right" class="smallText">'.$order->totals[$i]['title'].'</td>'."\n".'
												<td align="right" class="smallText" width="1" nowrap="nowrap"><nobr>'.$order->totals[$i]['text'].'</nobr></td>'."\n".'
											</tr>'."\n";
									}
								?>
					        </table>
			            </td>
			        </tr>
			    </table>
			</div>
			<br style="clear:both" />
		</td>
      </tr>
      <tr>
        <td colspan="2" align="right">
		<?php
			if (ACTIVATE_GIFT_SYSTEM == 'true')
				echo '<a class="button" href="'.href_link(FILENAME_GV_MAIL, get_all_get_params(array('cID', 'action')).'cID='.$order->customer['ID']).'">'.BUTTON_SEND_COUPON.'</a>';
				
   			echo '<a class="button" href="' .href_link(FILENAME_ORDERS, 'page='.$_GET['page'].'&oID='.$_GET['oID']).'">'.BUTTON_BACK.'</a>';?>
       </td>
      </tr>
	<?php
	} else
		include('includes/modules/order_overview.php');
	?>
    </table></td>
  </tr>
</table>
</div>
<?php 
if((defined('MODULE_PAYMENT_PI_CLICKANDBUY_STATUS') && MODULE_PAYMENT_PI_CLICKANDBUY_STATUS == 'True') OR (defined('MODULE_PAYMENT_PI_CLICKANDBUY_RECURRING_STATUS') && MODULE_PAYMENT_PI_CLICKANDBUY_RECURRING_STATUS == 'True')) {
	include_once('../lang/'.$_SESSION['language'].'/admin/pi_clickandbuy.php');
	?>
	<script type="text/javascript">
		$(function(){
			$.fx.speeds._default = 1000;
			$('#dialog_box').dialog({
				autoOpen:false,
				show:"fade",
				hide:"explode",
				width:850,
				height: 550,
				modal:true,
				position:['center', 50]
			});
			$('.cab_button').live('click', function(){
				$("#dialog_box").load($(this).attr('href')).dialog("open");
				return false;
			});
		})
	</script>
	<div title="ClickandBuy" id="dialog_box" style="display:none"></div>
<?php 
}
require (DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php');